<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zj="http://www.zju.edu.cn" exclude-result-prefixes="zj">
  <xsl:import href="ListFrame_Trans.xslt"/>
  <xsl:import href="../Tk2Base/PageListItems.xslt"/>
  <xsl:import href="../Tk2Base/ListItems.xslt"/>
  <xsl:import href="../Tk2Base/PublicItems.xslt"/>
  <xsl:variable name="zj:Toolkit" select="/Toolkit"/>
  <xsl:key name="zj:ToolkitData" match="/Toolkit/*" use="local-name()"/>
  <xsl:variable name="zj:XmlData" select="$Doc"/>
  <xsl:template name="zj:PostScript">
    <script language="JavaScript">
    function Post2()
    {
      var TableName = "<xsl:value-of select="$zj:XmlData/Toolkit/@Tables"/>";
      var FieldNames = "<xsl:value-of select="$zj:XmlData/Toolkit/@Fields"/>" + ",query";
      var guid = "<xsl:value-of select="$zj:Toolkit/Info/Guid"/>";
      PostData(TableName, FieldNames, "<xsl:value-of select="concat($zj:ListHeadUrl, $zj:ListOrder)"/>", guid, "");
    }
    function KeyUp(value, ctrl)
    {
      if (value == "")
        ctrl.value = "";
      else if (value == "~")
        ctrl.value = "~";
    }
    function changePage()
    {
        var eCtrl = window.event.srcElement;
        if (eCtrl == document.all('btnGoto', 0))
            eTmp = 0;
        else
            eTmp = 1;
        var pCtrl = document.all('MyPageID', eTmp);
        if (pCtrl == null) return;
        if (IsInteger(pCtrl.value) &amp;&amp; parseInt(pCtrl.value) > 0)
        {
            document.location.href = "<xsl:value-of select="concat($zj:ListHeadUrl, $zj:ListOrder)"/>" + "&amp;Page=" + pCtrl.value; 
        }
    }
    </script>
  </xsl:template>
  <xsl:template name="zj:ListTitle">
    <tr>
      <td class="title">
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="title">
              <xsl:call-template name="zj:PageTitle"/>
            </td>
            <td align="right">
              <img src="../images2/maintitle.jpg" width="220" height="23"/>
            </td>
          </tr>
          <tr>
            <td background="../images2/fix.gif" colspan="2" height="1"/>
          </tr>
        </table>
        <br/>
      </td>
    </tr>
  </xsl:template>
  <xsl:template name="zj:TabPage">
    <xsl:variable name="TabSheets" select="$zj:XmlData/Toolkit/zj:TabSheets/zj:TabSheet"/>
    <xsl:if test="boolean($TabSheets)">
      <xsl:variable name="SelectedTab" select="$TabSheets[@ID=$zj:Sort/Tab]"/>
      <xsl:variable name="SelectedTabName">
        <xsl:choose>
          <xsl:when test="boolean($SelectedTab)">
            <xsl:value-of select="$zj:Sort/Tab"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$TabSheets[1]/@ID"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="ListUrl" select="concat($zj:DSelfURL, 'cChar=', $zj:Sort/CChar,'&amp;ID=', $zj:Sort/ID, '&amp;Sort=', $zj:Sort/SortField, '&amp;Order=', $zj:RealOrder)"/>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style="CURSOR: default">
        <tr>
          <xsl:for-each select="$TabSheets">
            <td width="1%" height="22" background="../images2/lbx.gif" nowrap="nowrap">
              <xsl:attribute name="onClick">window.location='<xsl:value-of select="concat($ListUrl, '&amp;Tab=', @ID)"/>'</xsl:attribute>
              <xsl:if test="@ID=$SelectedTabName">
                <xsl:attribute name="background">../images2/lby.gif</xsl:attribute>
              </xsl:if>
              <a style="CURSOR: hand">
                <xsl:call-template name="zj:WhiteSpace"/>
                <xsl:call-template name="zj:WhiteSpace"/>
                <xsl:value-of select="@Title"/>
                <xsl:call-template name="zj:WhiteSpace"/>
                <xsl:call-template name="zj:WhiteSpace"/>
              </a>
            </td>
          </xsl:for-each>
          <td width="99%">
            <xsl:call-template name="zj:WhiteSpace"/>
          </td>
        </tr>
      </table>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:List">
    <xsl:variable name="FieldNodes" select="$zj:XmlData/Toolkit/zj:Table/List/zj:Field"/>
    <div id="divMaskLayer" >
    <table cellspacing="1" cellpadding="1" border="0" width="100%" class="listtb">
      <tr>
        <xsl:call-template name="zj:OperationHead"/>
        <xsl:apply-templates select="$FieldNodes" mode="zj:ListHead"/>
      </tr>
      <!--the DataList-->
      <xsl:variable name="Data" select="$zj:Toolkit/*[local-name()=current()/@TableName]"/>
      <xsl:choose>
        <xsl:when test="count($Data) &gt; 0">
          <xsl:call-template name="zj:ShowList">
            <xsl:with-param name="Data" select="$Data"/>
            <xsl:with-param name="FieldList" select="$FieldNodes"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="$zj:NoRecord"/>
        </xsl:otherwise>
      </xsl:choose>
    </table>
    </div>
  </xsl:template>
  <xsl:template name="zj:ShowList">
    <xsl:param name="Data"/>
    <xsl:param name="FieldList"/>
    <xsl:for-each select="$Data">
      <tr valign="top" class="td-bg" onmouseover="this.style.backgroundColor = '#F9F9F0';" onmouseout="this.style.backgroundColor = '';">
        <xsl:apply-templates select="$zj:XmlData/Toolkit/@Module" mode="zj:Operation">
          <xsl:with-param name="DataRecord" select="current()"/>
        </xsl:apply-templates>
        <xsl:apply-templates select="$FieldList" mode="zj:Item">
          <xsl:with-param name="DataRecord" select="."/>
        </xsl:apply-templates>
      </tr>
    </xsl:for-each>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:ListHead">
    <xsl:if test="not(zj:Display/@ListWidth) or zj:Display/@ListWidth &gt; 0">
      <xsl:choose>
        <xsl:when test="@DataType='text' or zj:Display/@TextHead='true'">
          <xsl:call-template name="zj:NoSortColHead">
            <xsl:with-param name="Title" select="zj:DisplayName"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="$zj:Sort/SortField=position()">
          <xsl:call-template name="zj:SortColHead">
            <xsl:with-param name="Title" select="zj:DisplayName"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="zj:ColHead">
            <xsl:with-param name="Title" select="zj:DisplayName"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:Item">
    <xsl:param name="DataRecord"/>
    <xsl:if test="not(zj:Display/@ListWidth) or zj:Display/@ListWidth &gt; 0">
      <xsl:call-template name="zj:DisplayListItem">
        <xsl:with-param name="DataRecord" select="$DataRecord"/>
        <xsl:with-param name="FieldList" select="$zj:XmlData/Toolkit/zj:Table/*/zj:Field"/>
        <xsl:with-param name="Source" select="$zj:Source"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template match="@Module" mode="zj:Operation">
    <xsl:param name="DataRecord"/>
    <xsl:call-template name="zj:Operation">
      <xsl:with-param name="Table" select="$zj:XmlData/Toolkit/zj:Table"/>
      <xsl:with-param name="DataRecord" select="$DataRecord"/>
      <xsl:with-param name="Source" select="$zj:Source"/>
      <xsl:with-param name="IsUpdate" select="not($zj:XmlData/Toolkit/zj:DisablePage/Update)"/>
      <xsl:with-param name="IsDelete" select="not($zj:XmlData/Toolkit/zj:DisablePage/Delete)"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="@Module[.='List2' or .='ListDetail2' or .='AllRow2']" mode="zj:Operation">
    <xsl:param name="DataRecord"/>
    <xsl:call-template name="zj:EmptyOperation"/>
  </xsl:template>
</xsl:stylesheet>
